const fp = require('lodash/fp')
const {Maybe, Container} = require('./support')

//练习1
let maybe = Maybe.of([5, 6, 1])
let ex1 = (arr) => fp.map((number) => number + 1, arr)
let result = maybe.map(ex1)
console.log(result)

//练习2
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])
let ex2 = (res) => {
    console.log(fp.first(res))
}
xs.map(ex2)

//练习3
let safeProp = fp.curry(function (x, o) {
    return Maybe.of(o[x])
})
let user = {id: 2, name: "Albert"}
let ex3 = (res) => {
    console.log(fp.first(res))
}
safeProp('name', user).map(ex3)

//练习4

// let ex4 = function (n) {
//     if (n) {
//         return parseInt(n)
//     }
// }
// let result4 = ex4(false)
// console.log(result4)

let ex4 = Maybe.of(456)
let result4 = ex4.map((n) => parseInt(n))
console.log(result4)
// 传入false 好像有问题的样子？？
boolean :includes(xx)    // 字符串是否包含xx
boolean :startsWith(xx)  // 以xx开头
boolean :endsWith(xx)    // 以xx结尾
